<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Image extends Admin_Controller {

	public function upload() {
		$uploader = new qqFileUploader();
		$uploader->inputName = 'qqfile';
		$uploader->chunksFolder = $this->_getImageDir() . 'chunks';
		$uploader->handleUpload($this->_getImageDir());

		$fileName = $uploader->getUploadName();
		$imgObj = App::object('Entity_Image');
		$imgObj->setFile($fileName)->save();
		$result = array(
			'id'  => $imgObj->getId(),
			'url' => $imgObj->resize(175)->getUrl(),
			'success' => true
		);

		header('Content-type: application/json');
		echo json_encode($result);
	}

	protected function _getImageDir() {
		return str_replace('system/','media/post/', BASEPATH);
	}
	
}
